//LOV外部定义变量
//var lovCurrentPage = 1; //第一页
//var lovDefaultPageSize = 10; //每页默认10行
//var lovPageSize = lovDefaultPageSize; // 
//var lovOption = {};
//lovOption.params = {};
//lovOption.lovname: lov名字 div名称前缀lovname_dialogbox
//lovOption.lovtitle:lov标题
//lovOption.lovyesbtn:确定
//lovOption.gridname:table grid名字 //div中table表名
function Lov(lovOption){
	lovOption.lovtitle='查询列表';
	saveOrUpdate(lovOption);
	loadGrid(lovOption);
}
function saveOrUpdate(lovOption){
	new Dialog({
			target:'#'+lovOption.lovname+"_dialogbox",
			width:800,
			height:640,
			showYesBtn:true,
			showNoBtn:true,
			title: lovOption.lovtitle,
			yesBtnText:'确定',
			noBtnText:'取消',
			yesFn:function(){},
			noFn:function(){}}).show();
}
function loadGrid(lovOption){
	//分页参数
	lovOption.params.currentPage = currentPage;
	lovOption.params.pageSize = pageSize;
	$.ajax({
		url: lovOption.url,
		type:'post',
		data:lovOption.params
	}).done(function(data){
		var result = data.bo;
		var pager = {};
		$("#"+lovOption.gridname+"").datagrid({
			fitColumns:true,
			singleSelect:true,
			pagination:true,
			remoteSort:false,
			multiSort:true,
			loadMsg:"数据加载中，请稍后……",
			data:result.list,
			columns:[lovOption.columns],
			      onSortColumn: function (sort, order) {
			    	  setPager(pager,result.total);
			      },
			 onSelect:lovOption.onSelect
		});
		var pager = $("#"+lovOption.gridname+"").datagrid().datagrid('getPager');	// get the pager of datagrid
		setPager(pager,result.total,lovOption);
	});
}
function setPager(pager,total,lovOption){
	pager.pagination({
		total:total,
		pageNumber:currentPage,
	    pageSize:pagesize,
	    layout:['first','prev','links','next','last'],
	    onSelectPage:function(cpage, psize){
	    	currentPage=cpage;
	    	pageSize=psize;
	    	loadGrid(lovOption);
		}
	});
}